package com.check.operation.base;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import androidx.appcompat.app.AppCompatActivity;

public abstract class BaseActivity extends AppCompatActivity {

    public static final String BARCODE_ACTION = "android.intent.action.BARCODEDATA";
    public static final String BARCODE_RESULT = "barcode_result";

    private BroadcastReceiver broadcastReceiver;

    private void initBarReceiver() {
        broadcastReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if(BARCODE_ACTION.equals(intent.getAction())) {
                    onGetBarValue(intent.getStringExtra(BARCODE_RESULT));
                }
            }
        };
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.BARCODEDATA");
        this.registerReceiver(broadcastReceiver, filter);
    }

    protected void onResume() {
        super.onResume();
        this.initBarReceiver();
    }

    protected void onPause() {
        super.onPause();
        this.unregisterReceiver(broadcastReceiver);
    }

    public abstract void onGetBarValue(String paramString);


}
